package com.eclink.iot.tcp.virtualdevice.util;


public class TimeUtil {

    /**
     * 把时间戳转换成4位的byte数组
     * @return byte数组
     */
    public static byte[] transTimestampToBytes(long timestamp) {
        byte[] byteArray = new byte[4];
        for(int i = 0; i < 4; i++) {
            byte b = (byte) ((timestamp >> ((3 - i) * 8)) & 0xFF);
            byteArray[i] = b;
        }
        return byteArray;
    }

    /**
     * 把时间戳转换成4位的byte数组
     * @return byte数组
     */
    public static byte[] transTimestampToBytes() {
        long timestamp = System.currentTimeMillis() / 1000;
        return transTimestampToBytes(timestamp);
    }

}
